{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ChipWhisperer Updating\n",
    "\n",
    "Did you just get a fresh VM? Sometimes you want updates from more recent changes, as the VM builds are not automatically handled.\n",
    "\n",
    "This notebook will show you how you can sync to the latest version of ChipWhisperer. Remember that the latest version is held in a GIT repo at [https://www.github.com/newaetech/chipwhisperer](https://www.github.com/newaetech/chipwhisperer).\n",
    "\n",
    "This notebook uses normal GIT commands to sync up your repo. You should be somewhat familiar with GIT before running all of these!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Note on File Paths\n",
    "\n",
    "Remember you are located in the `chipwhisperer/jupyter` directory. If you want to updated *everything*, you need to add a `cd ..` before the command.\n",
    "\n",
    "    jupyter <-- You are here, this is a submodule of 'chipwhisperer-jupyter'\n",
    "    ../ <-- This is the main ChipWhisperer repo"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Getting Normal ChipWhisperer Update\n",
    "\n",
    "This is done by doing a `git pull` and `git checkout` on the main ChipWhisperer tree:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "cd ..\n",
    "git add .\n",
    "git stash\n",
    "git pull\n",
    "git checkout\n",
    "git stash pop"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Updating Tutorials\n",
    "\n",
    "The main ChipWhisperer repo may not hold the latest version of the tutorials. If you'd like to sync to the latest possible version (generally they will be stable!), you can do it with the following command:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "mkdir -p jupyter-backup\n",
    "cp -rf courses demos experiments jupyter-backup\n",
    "git add .\n",
    "git stash\n",
    "git pull\n",
    "git checkout\n",
    "git stash pop"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**note:** If you've made changes to notebooks, they likely will not survive the update process. As such, the above command copies the courses, demos, and experiments folders to jupyter-backup. jupyter-backup is overwritten each time this is done, so it is recommended that you backup this folder before you run this block."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Switching to Training Branch\n",
    "\n",
    "You may need to switch the branch you are on for specific features. If following the online training on [ChipWhisperer.io](https://www.ChipWhisperer.io) you should use the `training-verions` branch. This branch is designed to follow the material on the labs and videos there as closely as possible (sometimes small updates and changes will be added).\n",
    "\n",
    "The following will switch the Jupyter notebooks to that branch. This step is **required if you are following the ChipWhisperer.io training**."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "git pull\n",
    "git checkout training-versions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Dealing with Merge Conflicts\n",
    "\n",
    "If you have run the notebooks, you may end up with merge conflicts. Generally if you have just been following along (not making edits you want to save), the easiest method is to throw away your changes.\n",
    "\n",
    "A quick-n-dirty method of throwing away specific notebooks is to explicitly checkout those files. For example if we had a conflict on `courses/sca101/Lab 2_1B - Power Analysis for Password Bypass (MAIN).ipynb` we could run:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "git checkout \"courses/sca101/Lab 2_1B - Power Analysis for Password Bypass (MAIN).ipynb\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can also checkout all `.ipynb` files if you're sure you have no changed files. This shouldn't delete any new ones:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%bash\n",
    "git checkout '*.ipynb'"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
